package hr.ctg.domain.model;

// Generated 2007.05.02 22:50:59 by Hibernate Tools 3.2.0.b9

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Immutable;
import org.hibernate.validator.NotNull;

/**
 * Posta generated by hbm2java
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Immutable
@Table(name = "posta")
@NamedQueries( {
		@NamedQuery(name = "Posta.findAllWithPbr", query = "SELECT p FROM Posta p WHERE p.postanskiBroj LIKE ? order by p.postanskiBroj"),
		@NamedQuery(name = "Posta.findAllInZupanija", query = "SELECT DISTINCT p FROM Mjesto m JOIN m.zupanija z JOIN m.posta p WHERE z.idZupanje = ? order by p.postanskiBroj"),
		@NamedQuery(name = "Posta.findAllInOtok", query = "SELECT DISTINCT p FROM Mjesto m JOIN m.otok o JOIN m.posta p WHERE o.idOtoka = ? order by p.postanskiBroj") })
public class Posta implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -691394957041611929L;
	private int idPoste;
	private String naziv;
	private String postanskiBroj;
	private Set<Mjesto> mjestos = new HashSet<Mjesto>(0);

	public Posta() {
	}

	public Posta(final int idPoste, final String naziv,
			final String postanskiBroj) {
		this.idPoste = idPoste;
		this.naziv = naziv;
		this.postanskiBroj = postanskiBroj;
	}

	public Posta(final int idPoste, final String naziv,
			final String postanskiBroj, final Set<Mjesto> mjestos) {
		this.idPoste = idPoste;
		this.naziv = naziv;
		this.postanskiBroj = postanskiBroj;
		this.mjestos = mjestos;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_poste", unique = true, nullable = false)
	@NotNull
	public int getIdPoste() {
		return idPoste;
	}

	public void setIdPoste(final int idPoste) {
		this.idPoste = idPoste;
	}

	@Column(name = "naziv", nullable = false)
	@NotNull
	public String getNaziv() {
		return naziv;
	}

	public void setNaziv(final String naziv) {
		this.naziv = naziv;
	}

	@Column(name = "postanski_broj", nullable = false)
	@NotNull
	public String getPostanskiBroj() {
		return postanskiBroj;
	}

	public void setPostanskiBroj(final String postanskiBroj) {
		this.postanskiBroj = postanskiBroj;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "posta")
	public Set<Mjesto> getMjestos() {
		return mjestos;
	}

	public void setMjestos(final Set<Mjesto> mjestos) {
		this.mjestos = mjestos;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idPoste;
		return result;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}

		final Posta other = (Posta) obj;
		if (idPoste != other.getIdPoste()) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return Integer.toString(idPoste);
	}

}
